package admin.student.dao;

import java.util.List;

import org.apache.ibatis.session.ExecutorType;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.mybatis.spring.support.SqlSessionDaoSupport;
import org.springframework.stereotype.Component;

import user.personal.domain.PersonalCommand;

import com.gwamok.domain.GwamokCommand;
import com.student.domain.StudentCommand;

@Component
public class StudentDaoImpl extends SqlSessionDaoSupport implements StudentDao{

	@Override
	public List<StudentCommand> getMemberList(String gwa_code) {
		List<StudentCommand> list = getSqlSession().selectList("getStudentList",gwa_code);
		return list;
	}
	
	@Override
	public List<GwamokCommand> getScheduleList(String hakbun){
		List<GwamokCommand> list = getSqlSession().selectList("getScheduleList",hakbun);
		return list;
	};

	@Override
	public int getMemberCount() {
		return 0;
	}

	@Override
	public void insertMember(StudentCommand studentCommand) {
		getSqlSession().insert("insertStudent",studentCommand);
	}

	@Override
	public StudentCommand getMember(String id) {
		StudentCommand studentCommand = getSqlSession().selectOne("getStudent",id);
		return studentCommand;
	}

	@Override
	public void updateMember(StudentCommand member) {
		getSqlSession().update("updateStudent",member);
	}

	@Override
	public void deleteMember(List<String> idList) {
		
		SqlSessionFactory sqlSessionFactory = 
				new SqlSessionFactoryBuilder().build(getSqlSession().getConfiguration());
		SqlSession session = sqlSessionFactory.openSession(ExecutorType.BATCH);

		try
		{
			for(String id:idList)
			{
				session.delete("deleteStudent",id);	
			}
			session.commit();
		}catch(Exception e)
		{
			e.printStackTrace();
			session.rollback();
		}finally
		{
			session.close();
		}
	}

	@Override
	public void updateStudent(PersonalCommand member) {
		getSqlSession().update("updatePersonal",member);
		
	}

	@Override
	public void modifyMember(PersonalCommand member) {
		getSqlSession().update("modifyStudent",member);
		
	}

	@Override
	public StudentCommand getStudentInfo(String id) {
		StudentCommand studentCommand = getSqlSession().selectOne("getstudentinfo",id);
		return studentCommand;
	}

}
